package com.yanqu.road.server.cmd.tradewar;

import com.yanqu.road.pb.tradewar.TradeWarProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.manger.player.TradeWarMgr;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.server.protocol.Protocol;
import com.yanqu.road.server.command.Cmd;

@Cmd(code = Protocol.S_TRADE_WAR_PUBLISH_WANTED, desc = "商战通缉列表")
public class TradeWarPublishWantedCmd extends AbstractCommand {

	private long wantedUserId;
	private int useItemId;

	@Override
	public boolean parseData(YanQuMessage packet) throws Exception {
		TradeWarProto.TradeWarPublishWantedReqMsg reqMsg = TradeWarProto.TradeWarPublishWantedReqMsg.parseFrom(packet.getBytes());
		wantedUserId = reqMsg.getWantedUserId();
		useItemId = reqMsg.getUseItemId();
		return true;
	}

	@Override
	public void execute(GamePlayer player, YanQuMessage packet) throws Exception {
		ret = TradeWarMgr.publishTradeWarWanted(player, wantedUserId, useItemId);
	}

	@Override
	public void sendData(GamePlayer player) {
		TradeWarProto.TradeWarPublishWantedRespMsg.Builder respMsg = TradeWarProto.TradeWarPublishWantedRespMsg.newBuilder();
		respMsg.setRet(ret);
		player.sendPacket(Protocol.U_TRADE_WAR_PUBLISH_WANTED, respMsg);
	}
}
